package com.amumu.drama.common.constant;

import com.google.common.collect.Maps;
import lombok.Getter;

import java.util.Arrays;
import java.util.Map;

/**
 * @author sunzhuang
 * @date 2024/5/13 20:28
 * @slogan 天下风云出我辈, 一入代码岁月催
 * @desc 订单状态
 * 福禄充值状态 0->1->2->3
 * 人工充值状态 0->1->2->3
 */
@Getter
public enum OrderStatusEnum {
    /**
     * 订单状态
     */
    WAIT_PAY(0, "待支付"),
    WAIT_DELIVERY(1, "待发货"),
    FINISHED(2, "已完成"),
    REFUND(3, "已退款"),
    CLOSED(4, "已关闭"),
    ;

    private Integer code;

    private String desc;

    private static Map<Integer, OrderStatusEnum> UNINDEX = Maps.uniqueIndex(Arrays.asList(values()), OrderStatusEnum::getCode);

    OrderStatusEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }


    public static OrderStatusEnum getByCode(Integer code) {
        if (code == null) {
            return null;
        }
        return UNINDEX.getOrDefault(code, null);
    }

}
